/**
 *
 */    //seriesname1;
   // seriesname2;
    //seriesname3;
$(document).ready(function() {
    Highcharts.setOptions({
        global: {
            useUTC: false
        },
        colors:['#F0382B','#28A1F6']
    });
    j = 0;
    $('#t1').click(function () {

    });
    var chart;
    var str = 'unnamed';
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'ct1',  //指向的div的id属性
            // backgroundColor: '#808080',
            type: 'spline',
            marginRight: 10,
            events: {
                load: function() {

                    // set up the updating of the chart each second
                    var series = this.series[0];
                    var series1 = this.series[1];
                    var YY = {
                        yy1: 1,
                        yy2: 2
                    };
                    alert(YY.yy1);
                    setInterval(function() {
                        var x = (new Date()).getTime(); // current time
                        getYY1(YY);
                        getYY2(YY);
                        // alert(YY.y1)
                        y1 = YY.yy1;
                        y2 = YY.yy2;
                        // addPoint 第二个参数表示是否对图表进行重绘，当有多个参数是，需先关闭重绘，
                        // 等操作完毕后再调 chart.redraw();

                        series.addPoint([x, y1], false, true);
                        series1.addPoint([x, y2], false, true);
                        chart.redraw();
                    }, 1000);
                }
            }
        },
        title: {
            text: '<b>综合应用设计</b>'
        },
        xAxis: {
            type: 'datetime',
            tickPixelInterval: 150  //x轴上的间隔
        },
        yAxis: [{
            title: {
                text: 'value'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#000000'
            }]
        }],
        tooltip: {
            formatter: function() {
                return '<b>'+ this.series.name +'</b><br/>'+
                    Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
                    Highcharts.numberFormat(this.y, 2);
            }
        },
        legend: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        credits: {
            enabled: false
        },
        series: [{
            name: 'Random data1',
            data:(function() {
                // generate an array of random data  
                var data1 = [],
                    time = (new Date()).getTime(),
                    i;
                for (i = -9; i <= 0; i++) {
                    data1.push({
                        x: time + i * 1000,
                        y: 0
                    });
                }
                return data1;
            })()
        },{
            name: 'Random data2',
            data:(function() {
                // generate an array of random data  
                var data2 = [],
                    time = (new Date()).getTime(),
                    i;
                for (i = -9; i <= 0; i++) {
                    data2.push({
                        x: time + i * 1000,
                        y: 0
                    });
                }
                return data2;
            })()
        }]
    });
});
function getYY1(theObject){
    $.ajax({
        type: "post",
        url: "http://localhost:8080/getPingInfo.action",
        data:{ipAddress:"127.0.0.1"},
        dataType: "json",

        success: function (res,status) {

            theObject.yy1 = parseInt(res.pingtime,10);
            alert(res.pingtime);
            alert(theObject.yy1);
            // console.log(data.data);
            alert(res.toip)
        },
        error: function(res,status,xhr){
            alert(xhr);
            alert(status);
            alert(res);
        }
    });
}
function getYY2(theObject){
    $.ajax({
        type: "post",
        url: "http://localhost:8080/getPingInfo.action",
        //data:{ipAddress:"127.0.0.1"},
        dataType: "json",

        success: function (res,status) {
            if(res.pingtime == null )
                theObject.yy2 = 0;
            else {
                theObject.yy2 = parseInt(res.pingtime,10);
                alert(res.pingtime);
                alert(theObject.yy2);
                // console.log(data.data);
                alert(res.toip)
            }
        },
        error: function(res,status,xhr){
            alert(xhr);
            alert(status);
            alert(res);
        }
    });
}